home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / bildschirmschoner / bserver_v1.5 / sources.lha / Sources / server / startclients.c < prev    next >
C/C++ Source or Header  |  1995-11-08  |  3KB  |  135 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <dos/dostags.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. #include <proto/exec.h>
  9. #include <proto/dos.h>
  10.  
  11. #include "/include/server.h"
  12.  
  13.  
  14. extern struct List ClientsList;
  15. extern UWORD TotalClients;
  16.  
  17. #define MAXCLIENTS 100
  18.  
  19. struct TagItem systags[4] = { SYS_Asynch, TRUE, SYS_Input, NULL, SYS_Output, NULL, TAG_END };
  20.  
  21.  
  22. BOOL StartClient( struct ClientNode *node )
  23. {
  24. BPTR lock, oldlock;
  25. char path[256], *cp;
  26. BOOL result = FALSE;
  27.  
  28. if ( lock = Lock( node->cn_ClientProg, ACCESS_READ ) )
  29.     {
  30.     UnLock( lock );
  31.     strcpy( path, node->cn_ClientProg );
  32.  
  33.     cp = path + strlen( path ) -1;
  34.     while( cp > path && *cp != '/' && *cp != ':' )
  35.         cp--;
  36.     if ( cp > path )
  37.         {
  38.         *cp = 0;
  39.         cp++;
  40.         }
  41.     lock = Lock( path, ACCESS_READ );
  42.     oldlock = CurrentDir( lock );
  43.     if ( SystemTagList( cp, systags ) != -1 )
  44.         result = TRUE;
  45.     CurrentDir( oldlock );
  46.     }
  47. return result;
  48. }
  49.  
  50.  
  51. void AddClient( char *newclient, char *newprog, char *newargs )
  52. {
  53. struct ClientNode *node;
  54.  
  55. if ( node = AllocVec( sizeof(struct ClientNode), MEMF_ANY | MEMF_CLEAR ) )
  56.     {
  57.     strcpy( node->cn_ClientName, newclient );
  58.     strcpy( node->cn_ClientProg, newprog );
  59.     if ( newargs )
  60.         strcpy( node->cn_ClientArgs, newargs );
  61.     node->cn_Node.ln_Name = node->cn_ClientName;
  62.     AddTail( &ClientsList, (struct Node *)node );
  63.     TotalClients++;
  64.     }
  65. }
  66.  
  67.  
  68. struct FileInfoBlock fib;
  69.  
  70. void GetClientNames( char *listname )
  71. {
  72. BPTR handle;
  73. register ULONG size;
  74. register char *ptr, *current, newclient[CLIENTNAME_MAXLENGTH],
  75.               newprog[PROGNAME_MAXLENGTH], newargs[ARGS_MAXLENGTH];
  76. register UBYTE n;
  77.  
  78. if ( handle = Open( listname, MODE_OLDFILE ) )
  79.     {
  80.     if ( ExamineFH( handle, &fib ) )
  81.         {
  82.         size = fib.fib_Size;
  83.         if ( ptr = AllocVec( (size + 1), MEMF_ANY | MEMF_CLEAR ) )
  84.             {
  85.             Read( handle, ptr, size );
  86.  
  87.             current = ptr;
  88.             while( *current )
  89.                 {
  90.                 n = 0;
  91.                 while( *current && *current != ':' && n < CLIENTNAME_MAXLENGTH )
  92.                     newclient[n++] = *current++;
  93.                 newclient[n] = 0;
  94.  
  95.                 while ( *(++current) && *current == ' ' );
  96.  
  97.                 n = 0;
  98.                 while ( *current && *current != '\n' && *current != ' ' && n < PROGNAME_MAXLENGTH )
  99.                     newprog[n++] = *current++;
  100.                 newprog[n] = 0;
  101.  
  102.                 if ( *current++ == '\n' )
  103.                     newargs[0] = NULL;
  104.                 else
  105.                     {
  106.                     n = 0;
  107.                     while ( *current && *current == ' ' )
  108.                         current++;
  109.                     while ( *current && *current != '\n' && n < ARGS_MAXLENGTH )
  110.                         newargs[n++] = *current++;
  111.                     newargs[n] = 0;
  112.                     current++;
  113.                     }
  114.                 if ( newclient[0] && newprog[0] )
  115.                     AddClient( newclient, newprog, newargs );
  116.                 }
  117.             FreeVec( ptr );
  118.             }
  119.         }
  120.     Close( handle );
  121.     }
  122. }
  123.  
  124.  
  125. void DropClientNames( void )
  126. {
  127. struct ClientNode *node;
  128.  
  129. while ( node = (struct ClientNode *)RemHead( &ClientsList ) )
  130.     {
  131.     FreeVec( node->cn_ClientArgs );
  132.     FreeVec( node );
  133.     }
  134. }
  135.